home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
getname.zip
/
GETNAME.C
< prev
next >
Wrap
Text File
|
1986-11-07
|
2KB
|
60 lines
/**
getname - locates the name of the program as loaded by MS-DOS.
This is done by locating the end of the MS-DOS environment
table, and examining what follows. According to the DOS
Technical Reference Manual, beginning with DOS 3.10:
Load or Execute a Program (EXEC) - Function 4BH
"Following the byte of zero [which follows the last ASCIIZ
string] in the environment, is a WORD that indicates the
number of other strings following. Following this is a copy
of the DS:DX filename passed to the child process."
Function call 4BH includes a pointer (DS:DX) to an ASCIIZ
string which specifies the module to be loaded. It may contain
a fully qualified drive/path/name/extension, or less. Since
COMMAND.COM uses Interrupt 21H, function 4BH to load new
programs, this module should work on any system using DOS 3.10
or above. It most definitely does NOT work for DOS 3.00 or
earlier.
Public Domain by Peter Diehr to demonstrate how the module name
can be retrieved. If converted to subroutine form, this module
can be called by a Lattice C program, version 3.00 or later.
Written November 6, 1986 in Ann Arbor, Michigan.
**/
/**/
#include <stdio.h>
void main(argc,argv,envp)
int argc;
char *argv[];
char *envp[];
{
extern char _DOS[2]; /* DOS version & level */
extern char *environ[]; /* Environment pointer table address*/
char *q; /* used to manipulate strings */
char **tmp; /* used to manipulate pointer array*/
int i;
for(tmp=environ[0];*tmp;q=*tmp,tmp++) /* find end of environment */
;
for(;*q;q++) /* locate the end of environment */
; /* q points at the last env.string*/
q++; /* push past 0 byte at end of string*/
q++; /* push past 0 string at end of table*/
i=*(int *)q; /* pointer to counter WORD */
q++;q++; /* push past WORD in two steps*/
if(_DOS[0] >= 3 && _DOS[1] > 0 && i > 0) /* must be DOS 3.10 +*/
{
printf("\nDOS Version %d.%d stored the name ",_DOS[0],_DOS[1]);
printf("\nIt was first among %d string(s) following the environment\n%s",i,q);
printf("\nLattice C passed a name of %s",argv[0]);
}
else
{
printf("\nDOS Version %d.%d did not store the name\n",_DOS[0],_DOS[1]);
printf("String count was %d",i);
printf("\nLattice C passed a name of %s",argv[0]);
}
}